﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

using EnterpriseDT.Net.Ftp;

namespace FreeboxHDVideoPlayer
{
    public class ListVideoWorker : AbstractWorker
    {
        public ListVideoWorker(string host, int port, string user, string password)
            : base(host, port, user, password)
        {
        }

        protected override void OnDoWork(DoWorkEventArgs e)
        {
            List<Video> videos = new List<Video>();
            ReportProgress(0, "Connection au serveur...");
            using (FreeBoxHDFTP ftp = new FreeBoxHDFTP(this.Host, this.Port, this.User, this.Password))
            {
                ftp.Connect();
                ftp.Login();
                ftp.GotoVideoHome();
                ReportProgress(0, "Découverte des fichiers...");
                FTPFile[] files = ftp.FTPClient.DirDetails();
                long allocSize = 0;
                ReportProgress(0, "Parcours des fichiers...");
                foreach (FTPFile file in files)
                {
                    if (!file.Dir)
                    {
                        allocSize += file.Size;
                        videos.Add(new Video(file.Name, file.Size));
                    }
                }
                Result result = new Result();
                result.Size = allocSize;
                result.Videos = videos;
                e.Result = result;
            }
        }

        public class Result
        {
            public long Size
            {
                set;
                get;
            }

            public List<Video> Videos
            {
                get;
                set;
            }
        }

    }
}
